//
//  EngineManager.m
//  TestGameEngine
//
//  Created by Louis CHU on 20/03/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "EngineManager.h"
//#import "GameManager.h"
#import "RenderManager.h"
#import "UpdaterManager.h"
static const float kEngineManagerAnimationFrameInterval = 1.;

static EngineManager * sSharedEngineManager;

@interface EngineManager ()

@property (nonatomic, strong) NSTimer * timer;
@property (nonatomic, unsafe_unretained) float elapsedTime;

@end

@implementation EngineManager
@synthesize timer;
@synthesize elapsedTime;

+ (EngineManager *) sharedEngineManager
{
    
    if (!sSharedEngineManager) {
        sSharedEngineManager = [EngineManager new];
    }
    return sSharedEngineManager;
}

- (id) init
{
    self = [super init];
    if (self) {
        self.elapsedTime = (1.0 / 24.0) * kEngineManagerAnimationFrameInterval;
    }
    return self;
}

- (void) start
{
    self.timer = [NSTimer scheduledTimerWithTimeInterval:(NSTimeInterval)self.elapsedTime target:[EngineManager sharedEngineManager] selector:@selector(update) userInfo:nil repeats:TRUE];
     
}

- (void) stop
{
    [self.timer invalidate];
    self.timer = nil;
}

- (void) update
{
    [[UpdaterManager sharedUpdaterManager] update:self.elapsedTime];
}
@end
